<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let userService = (function () {
        let cashed = new Map()
        return {
          getById: function (id) {
            if (cashed.has(id)) {
              console.log('查快速的东西')

              return cashed.get(id)
            } else {
              console.log('查慢速的东西')
              let value = Math.random()
              cashed.set(id, value)
              return value
            }
          },
        }
      })()

      let result = userService.getById(100)
      console.log('1:', result)
      let result2 = userService.getById(100)
      console.log('2:', result2)
    </script>
  </body>
</html>
